package com.ruoyi.warning.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.warning.domain.entity.Eventlog;
import com.ruoyi.warning.domain.query.EventLogQuery;
import com.ruoyi.warning.mapper.EventlogMapper;
import com.ruoyi.warning.service.IEventlogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenhc
 * @since 2025-04-02
 */
@Service
public class EventlogServiceImpl extends ServiceImpl<EventlogMapper, Eventlog> implements IEventlogService {

    @Resource
    private EventlogMapper eventlogMapper;
    @Override
    public Object getLog(EventLogQuery query) {
        Page<Eventlog> page = PageHelper.startPage(query.getPageNum(),query.getPageSize());
        LambdaQueryWrapper<Eventlog> wrapper = new QueryWrapper<Eventlog>().lambda()
                .like(query.getId() != null,Eventlog::getDeviceId,query.getId())
                .orderByDesc(Eventlog::getDatetime);
        List<Eventlog> list = this.list(wrapper);
        TableDataInfo tableDataInfo = new TableDataInfo(list, page.getTotal());
        return tableDataInfo;
    }
}
